var path = require('path')
var routerApi = require('../../utils/routeString.js')(__filename, __dirname);

var exportFn = require('../../utils/dataExport.js')
var jwt = require('../../utils/jwt.js')

server.get({ path: routerApi, name: routerApi }, async function (req, res, next) {
    var body = req.body || req.query;

    if (!body.token || !body.tableName) {
        return res.send({ code: 0, msg: "参数错误" })

    }

    try {
        if (body.tableName != 'checkin') body.uid = null;
        let jwtData = await jwt.decode(body.token);
        let fileData = await exportFn(body.tableName, 'excel', body.uid); // where {uid:123}
        res.setHeader("Content-Disposition", "attachment;filename=" + body.tableName + ".xls");
        res.setHeader('Content-Type', 'text/txt');
        res.send(fileData.data.toString());
    } catch (error) {
        console.log(error);
        res.send({ code: 0, msg: error });
    }


});

